function submitType() {
    const name = $('#name').val();
    if (name == null || name.length === 0) {
        alert("分类名称不为空!")
        return;
    }
    const data = {'name': name}
    const typeId = $('#id');
    const id = typeId.val();
    if (id !== '') {
        data['id'] = id;
        typeId.val('');
    }
    $.ajax({
        type: 'POST',
        url: '/admin/types/save',
        data: data,
        async: false,
        success: function (result) {
            alert(result.msg)
        }
    })
    // $('#submitModal').modal('hide');
    window.location.href = '';
}

function deleteType(id) {
    if (!confirm("确认删除该分类？")) return;
    if (isNaN(id)) return;
    $.ajax({
        type: 'POST',
        url: '/admin/types/delete',
        data: {
            'id': id
        },
        async: false,
        success: function (result) {
            alert(result.msg)
        }
    })
    window.location.href = '';
}

function modifyType(id) {
    if (isNaN(id)) return;
    const typeName = $('#name-' + id);
    if (typeName == null) return;
    console.log('=============' + id);
    const inputName = $('#name');
    inputName.val(typeName.text());
    $('#id').val(id);
}

/**
 * modal 关闭监听
 * */
$('#submitModal').on('hidden.bs.modal', function () {
    $('#id').val('');
    $('#name').val('')
})